<?php

namespace App\Http\Controllers\Api;

use App\Models\MsgBoard;
use Illuminate\Http\Request;

class MsgBoardController extends Controller
{
    public function store(Request $request)
    {
        $content = $request->input('content');
        if (!$content) return $this->error('内容不能为空');

        MsgBoard::create([
            'mini_type' => $this->getMiniType(),
            'member_id' => auth('api')->user()->id,
            'content'   => $content,
        ]);

        return $this->success('留言成功');
    }

    public function list(Request $request)
    {
        $list = MsgBoard::select(['id', 'content', 're_content', 'state', 'created_at'])->where([
            'mini_type' => $this->getMiniType(),
            'member_id' => auth('api')->user()->id,
        ])->orderBy('id')->paginate();

        return $this->_success([
            'list' => $list->items()
        ]);
    }
}
